package com.iknow.xmpp.service;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
import android.util.Log;
import com.iknow.IKnow;
import com.iknow.IKnowApiV4;
import com.iknow.activity.IKnowActivity;
import com.iknow.db.IKnowDataBase;
import com.iknow.http.HttpException;
import com.iknow.util.Loger;
import com.iknow.xmpp.extention.Ping;
import com.iknow.xmpp.service.aidl.IBeemConnectionListener;
import com.iknow.xmpp.service.aidl.IChatManager;
import com.iknow.xmpp.service.aidl.IKnowUser;
import com.iknow.xmpp.service.aidl.IRoster;
import com.iknow.xmpp.service.aidl.IXmppConnection.Stub;
import com.iknow.xmpp.service.aidl.IXmppFacade;
import com.iknow.xmpp.smack.avatar.AvatarListener;
import com.iknow.xmpp.smack.avatar.AvatarMetadataExtension.Info;
import com.iknow.xmpp.smack.pep.PepSubManager;
import com.iknow.xmpp.util.Status;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.ConnectionListener;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.PrivacyListManager;
import org.jivesoftware.smack.Roster;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.packet.IQ.Type;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Presence.Mode;
import org.jivesoftware.smack.packet.Presence.Type;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smackx.ChatStateManager;
import org.jivesoftware.smackx.ServiceDiscoveryManager;
import org.jivesoftware.smackx.packet.DiscoverInfo;
import org.jivesoftware.smackx.packet.DiscoverInfo.Identity;
import org.json.JSONException;
import org.json.JSONObject;

public class XmppConnectionAdapter extends IXmppConnection.Stub
{
  private static final int SMACK_PRIORITY_MAX = 128;
  private static final int SMACK_PRIORITY_MIN = -128;
  private static final String TAG = "XMPPConnectionAdapter";
  private PacketFilter PingFilter;
  private final XMPPConnection mAdaptee;
  private IKnow mApplication;
  private IKnowAvatarManager mAvatarManager;
  private IChatManager mChatManager;
  private ChatStateManager mChatStateManager;
  private final ConnexionListenerAdapter mConListener;
  private String mErrorMsg;
  private IKnowUser mIKnowUser;
  private String mLogin;
  private String mPassword;
  private PepSubManager mPepManager;
  private final PingPacketListener mPingPacketListener;
  private SharedPreferences mPref;
  private int mPreviousMode;
  private int mPreviousPriority;
  private String mPreviousStatus;
  private PrivacyListManagerAdapter mPrivacyListManager;
  boolean mReconnectionStoped;
  private final RemoteCallbackList<IBeemConnectionListener> mRemoteConnListeners;
  private String mResource;
  private RosterAdapter mRoster;
  private final IKnowXmppService mService;
  private final SubscribePacketListener mSubscribePacketListener;
  private UserInfo mUserInfo;

  public XmppConnectionAdapter(String paramString1, String paramString2, String paramString3, IKnowXmppService paramIKnowXmppService)
  {
    this(new XMPPConnection(paramString1), paramString2, paramString3, paramIKnowXmppService);
  }

  public XmppConnectionAdapter(ConnectionConfiguration paramConnectionConfiguration, String paramString1, String paramString2, IKnowXmppService paramIKnowXmppService)
  {
    this(new XMPPConnection(paramConnectionConfiguration), paramString1, paramString2, paramIKnowXmppService);
  }

  public XmppConnectionAdapter(XMPPConnection paramXMPPConnection, String paramString1, String paramString2, IKnowXmppService paramIKnowXmppService)
  {
    this.mReconnectionStoped = false;
    this.mRemoteConnListeners = new RemoteCallbackList();
    this.mSubscribePacketListener = new SubscribePacketListener(this);
    this.mPingPacketListener = new PingPacketListener(this, null);
    this.mConListener = new ConnexionListenerAdapter(this);
    this.PingFilter = new PacketFilter(this)
    {
      public boolean accept()
      {
        int i;
        if (paramPacket instanceof Ping)
          i = 1;
        while (true)
        {
          return i;
          i = 0;
        }
      }
    };
    this.mAdaptee = paramXMPPConnection;
    PrivacyListManager.getInstanceFor(this.mAdaptee);
    this.mLogin = paramString1;
    this.mPassword = paramString2;
    this.mService = paramIKnowXmppService;
    Context localContext = this.mService.getApplicationContext();
    if (localContext instanceof IKnow)
      this.mApplication = ((IKnow)localContext);
    this.mPref = this.mService.getServicePreference();
    try
    {
      this.mPreviousPriority = Integer.parseInt(this.mPref.getString("connection_priority", "0"));
      this.mResource = this.mPref.getString("connection_resource", "iKnow_Android");
      return;
    }
    catch (NumberFormatException localNumberFormatException)
    {
      this.mPreviousPriority = 0;
    }
  }

  private boolean bindSession()
  {
    int i;
    JSONObject localJSONObject;
    try
    {
      localJSONObject = IKnow.mApi.requestSession();
      if (!(localJSONObject.has("user")))
      {
        String str = localJSONObject.getString("sid");
        IKnow.mApi.setSessionID(str);
        this.mIKnowUser.bindSession(str);
        Loger.i("XMPPConnectionAdapter", "bind session : " + str);
      }
      i = 1;
      return i;
    }
    catch (HttpException localHttpException)
    {
      Loger.e("XMPPConnectionAdapter", localHttpException.getMessage());
      localHttpException.printStackTrace();
      i = 0;
    }
    catch (RemoteException localRemoteException)
    {
      while (true)
      {
        Loger.e("XMPPConnectionAdapter", localRemoteException.getMessage());
        localRemoteException.printStackTrace();
      }
    }
    catch (JSONException localJSONException)
    {
      while (true)
        localJSONException.printStackTrace();
    }
  }

  private void discoverServerFeatures()
  {
    Iterator localIterator;
    try
    {
      DiscoverInfo.Identity localIdentity;
      localIterator = ServiceDiscoveryManager.getInstanceFor(this.mAdaptee).discoverInfo(this.mAdaptee.getServiceName()).getIdentities();
      do
      {
        if (!(localIterator.hasNext()))
          return;
        localIdentity = (DiscoverInfo.Identity)localIterator.next();
      }
      while ((!("pubsub".equals(localIdentity.getCategory()))) || (!("pep".equals(localIdentity.getType()))));
      initPEP();
    }
    catch (XMPPException localXMPPException)
    {
      Log.w("XMPPConnectionAdapter", "Unable to discover server features", localXMPPException);
    }
  }

  private void initFeatures()
  {
    ServiceDiscoveryManager.setIdentityName("iKnow_Android");
    ServiceDiscoveryManager.setIdentityType("phone");
    ServiceDiscoveryManager localServiceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(this.mAdaptee);
    if (localServiceDiscoveryManager == null)
      localServiceDiscoveryManager = new ServiceDiscoveryManager(this.mAdaptee);
    localServiceDiscoveryManager.addFeature("http://jabber.org/protocol/disco#info");
    localServiceDiscoveryManager.addFeature("http://jabber.org/protocol/caps");
    localServiceDiscoveryManager.addFeature("urn:xmpp:avatar:metadata");
    localServiceDiscoveryManager.addFeature("urn:xmpp:avatar:metadata+notify");
    localServiceDiscoveryManager.addFeature("urn:xmpp:avatar:data");
    localServiceDiscoveryManager.addFeature("http://jabber.org/protocol/nick");
    localServiceDiscoveryManager.addFeature("http://jabber.org/protocol/nick+notify");
    this.mChatStateManager = ChatStateManager.getInstance(this.mAdaptee);
  }

  private void initPEP()
  {
  }

  private void resetApplication()
  {
    this.mApplication.setConnected(false);
    this.mApplication.setPepEnabled(false);
    this.mApplication.setSessionBinded(false);
    IKnow.mIKnowDataBase.setAllRosterPresence(200);
    if (this.mApplication.isAccountConfigured())
      startReconnecitonThread();
  }

  private void updateNotification(Presence.Type paramType, String paramString)
  {
    Notification localNotification;
    if (paramType == Presence.Type.unavailable)
      localNotification = new Notification(2130837700, paramString, System.currentTimeMillis());
    while (true)
    {
      localNotification.defaults = 4;
      localNotification.flags = 34;
      localNotification.setLatestEventInfo(this.mService, "iKnow", paramString, PendingIntent.getActivity(this.mService, 0, new Intent(this.mService, IKnowActivity.class), 0));
      this.mService.getNotificationManager().notify(100, localNotification);
      return;
      localNotification = new Notification(2130837702, paramString, System.currentTimeMillis());
    }
  }

  public void addConnectionListener(IBeemConnectionListener paramIBeemConnectionListener)
    throws RemoteException
  {
    if (paramIBeemConnectionListener != null)
      this.mRemoteConnListeners.register(paramIBeemConnectionListener);
  }

  public boolean authenticatContentUser()
  {
    return bindSession();
  }

  public void changeStatus(int paramInt, String paramString)
  {
    changeStatusAndPriority(paramInt, paramString, this.mPreviousPriority);
  }

  public void changeStatusAndPriority(int paramInt1, String paramString, int paramInt2)
  {
    String str;
    Presence localPresence = new Presence(Presence.Type.available);
    if (paramString != null)
    {
      str = paramString;
      localPresence.setStatus(str);
      this.mPreviousStatus = str;
      Presence.Mode localMode = Status.getPresenceModeFromStatus(paramInt1);
      if (localMode == null)
        break label112;
      localPresence.setMode(localMode);
      this.mPreviousMode = paramInt1;
      int i = paramInt2;
      if (paramInt2 < -128)
        i = -128;
      if (paramInt2 > 128)
        i = 128;
      this.mPreviousPriority = i;
      localPresence.setPriority(i);
    }
    try
    {
      while (true)
      {
        this.mAdaptee.sendPacket(localPresence);
        return;
        str = this.mPreviousStatus;
      }
      label112: localPresence.setMode(Status.getPresenceModeFromStatus(this.mPreviousMode));
    }
    catch (IllegalStateException localIllegalStateException)
    {
      Loger.e("XMPPConnectionAdapter", localIllegalStateException.getMessage());
      try
      {
        this.mAdaptee.disconnect();
      }
      catch (Exception localException)
      {
        Loger.e("XMPPConnectionAdapter", localException.getMessage());
      }
    }
  }

  // ERROR //
  public boolean connect()
    throws RemoteException
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 119	com/iknow/xmpp/service/XmppConnectionAdapter:mAdaptee	Lorg/jivesoftware/smack/XMPPConnection;
    //   4: invokevirtual 504	org/jivesoftware/smack/XMPPConnection:isConnected	()Z
    //   7: ifne +13 -> 20
    //   10: aload_0
    //   11: getfield 119	com/iknow/xmpp/service/XmppConnectionAdapter:mAdaptee	Lorg/jivesoftware/smack/XMPPConnection;
    //   14: invokevirtual 507	org/jivesoftware/smack/XMPPConnection:isAuthenticated	()Z
    //   17: ifeq +7 -> 24
    //   20: iconst_1
    //   21: istore_1
    //   22: iload_1
    //   23: ireturn
    //   24: aload_0
    //   25: getfield 119	com/iknow/xmpp/service/XmppConnectionAdapter:mAdaptee	Lorg/jivesoftware/smack/XMPPConnection;
    //   28: invokevirtual 509	org/jivesoftware/smack/XMPPConnection:connect	()V
    //   31: aload_0
    //   32: getfield 119	com/iknow/xmpp/service/XmppConnectionAdapter:mAdaptee	Lorg/jivesoftware/smack/XMPPConnection;
    //   35: aload_0
    //   36: getfield 114	com/iknow/xmpp/service/XmppConnectionAdapter:mConListener	Lcom/iknow/xmpp/service/XmppConnectionAdapter$ConnexionListenerAdapter;
    //   39: invokevirtual 512	org/jivesoftware/smack/XMPPConnection:addConnectionListener	(Lorg/jivesoftware/smack/ConnectionListener;)V
    //   42: iconst_1
    //   43: istore_1
    //   44: goto -22 -> 22
    //   47: astore 5
    //   49: ldc 31
    //   51: ldc_w 514
    //   54: aload 5
    //   56: invokestatic 517	com/iknow/util/Loger:e	(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)V
    //   59: aload_0
    //   60: aload 5
    //   62: invokevirtual 521	org/jivesoftware/smack/XMPPException:getXMPPError	()Lorg/jivesoftware/smack/packet/XMPPError;
    //   65: invokevirtual 524	org/jivesoftware/smack/packet/XMPPError:getMessage	()Ljava/lang/String;
    //   68: putfield 526	com/iknow/xmpp/service/XmppConnectionAdapter:mErrorMsg	Ljava/lang/String;
    //   71: aload_0
    //   72: getfield 114	com/iknow/xmpp/service/XmppConnectionAdapter:mConListener	Lcom/iknow/xmpp/service/XmppConnectionAdapter$ConnexionListenerAdapter;
    //   75: invokevirtual 529	com/iknow/xmpp/service/XmppConnectionAdapter$ConnexionListenerAdapter:reconnect	()V
    //   78: iconst_0
    //   79: istore_1
    //   80: goto -58 -> 22
    //   83: astore 6
    //   85: ldc_w 531
    //   88: aload 5
    //   90: invokevirtual 532	org/jivesoftware/smack/XMPPException:getMessage	()Ljava/lang/String;
    //   93: invokevirtual 305	java/lang/String:equals	(Ljava/lang/Object;)Z
    //   96: ifne +15 -> 111
    //   99: aload_0
    //   100: aload 5
    //   102: invokevirtual 532	org/jivesoftware/smack/XMPPException:getMessage	()Ljava/lang/String;
    //   105: putfield 526	com/iknow/xmpp/service/XmppConnectionAdapter:mErrorMsg	Ljava/lang/String;
    //   108: goto -37 -> 71
    //   111: aload_0
    //   112: aload 5
    //   114: invokevirtual 533	org/jivesoftware/smack/XMPPException:toString	()Ljava/lang/String;
    //   117: putfield 526	com/iknow/xmpp/service/XmppConnectionAdapter:mErrorMsg	Ljava/lang/String;
    //   120: goto -49 -> 71
    //   123: astore 4
    //   125: ldc 31
    //   127: aload 4
    //   129: invokevirtual 534	java/lang/IllegalThreadStateException:getMessage	()Ljava/lang/String;
    //   132: invokestatic 256	com/iknow/util/Loger:e	(Ljava/lang/String;Ljava/lang/String;)V
    //   135: goto -64 -> 71
    //   138: astore_3
    //   139: ldc 31
    //   141: aload_3
    //   142: invokevirtual 492	java/lang/IllegalStateException:getMessage	()Ljava/lang/String;
    //   145: invokestatic 256	com/iknow/util/Loger:e	(Ljava/lang/String;Ljava/lang/String;)V
    //   148: goto -77 -> 71
    //   151: astore_2
    //   152: aload_0
    //   153: aload_2
    //   154: invokevirtual 535	java/lang/NullPointerException:getMessage	()Ljava/lang/String;
    //   157: putfield 526	com/iknow/xmpp/service/XmppConnectionAdapter:mErrorMsg	Ljava/lang/String;
    //   160: goto -89 -> 71
    //
    // Exception table:
    //   from	to	target	type
    //   24	42	47	org/jivesoftware/smack/XMPPException
    //   59	71	83	java/lang/NullPointerException
    //   24	42	123	java/lang/IllegalThreadStateException
    //   24	42	138	java/lang/IllegalStateException
    //   24	42	151	java/lang/NullPointerException
  }

  public final void connectAsync()
    throws RemoteException
  {
    if ((this.mAdaptee.isConnected()) || (this.mAdaptee.isAuthenticated()));
    while (true)
    {
      return;
      new Thread(new Runnable(this)
      {
        public void run()
        {
          try
          {
            this.this$0.connectSync();
            return;
          }
          catch (RemoteException localRemoteException)
          {
            Loger.e("XMPPConnectionAdapter", "Error while connecting asynchronously", localRemoteException);
          }
        }
      }).start();
    }
  }

  public boolean connectSync()
    throws RemoteException
  {
    boolean bool;
    if (connect())
      bool = login();
    while (true)
    {
      return bool;
      bool = false;
    }
  }

  public boolean disconnect()
  {
    if ((this.mAdaptee != null) && (this.mAdaptee.isConnected()));
    try
    {
      this.mAdaptee.disconnect();
      return true;
    }
    catch (Exception localException)
    {
      Loger.e("XMPPConnectionAdapter", localException.getMessage());
    }
  }

  public XMPPConnection getAdaptee()
  {
    return this.mAdaptee;
  }

  public IKnowAvatarManager getAvatarManager()
  {
    return this.mAvatarManager;
  }

  public IChatManager getChatManager()
    throws RemoteException
  {
    return this.mChatManager;
  }

  public String getErrorMessage()
  {
    return this.mErrorMsg;
  }

  public IKnowUser getIKnowUser()
    throws RemoteException
  {
    return this.mIKnowUser;
  }

  public int getPreviousMode()
  {
    return this.mPreviousMode;
  }

  public String getPreviousStatus()
  {
    return this.mPreviousStatus;
  }

  public PrivacyListManagerAdapter getPrivacyListManager()
  {
    return this.mPrivacyListManager;
  }

  public IRoster getRoster()
    throws RemoteException
  {
    RosterAdapter localRosterAdapter;
    if (this.mRoster != null)
      localRosterAdapter = this.mRoster;
    while (true)
    {
      Roster localRoster;
      while (true)
      {
        return localRosterAdapter;
        localRoster = this.mAdaptee.getRoster();
        if (localRoster != null)
          break;
        localRosterAdapter = null;
      }
      this.mRoster = new RosterAdapter(localRoster, this.mAdaptee, this.mIKnowUser, this.mService, this.mAvatarManager);
      localRosterAdapter = this.mRoster;
    }
  }

  public UserInfo getUserInfo()
  {
    return this.mUserInfo;
  }

  public XMPPConnection getXMPPConnection()
  {
    return this.mAdaptee;
  }

  public boolean isAuthentificated()
  {
    return this.mAdaptee.isAuthenticated();
  }

  public boolean login()
  {
    int i;
    if (this.mAdaptee.isAuthenticated())
      i = 1;
    while (true)
    {
      return i;
      if (this.mAdaptee.isConnected())
        break;
      i = 0;
    }
    try
    {
      initFeatures();
      2 local2 = new PacketFilter(this)
      {
        public boolean accept()
        {
          int i;
          if (paramPacket instanceof Presence)
            i = 1;
          while (true)
          {
            return i;
            i = 0;
          }
        }
      };
      this.mAdaptee.addPacketListener(this.mSubscribePacketListener, local2);
      this.mAdaptee.addPacketListener(this.mPingPacketListener, this.PingFilter);
      Loger.i("XMPPConnectionAdapter", "user login:" + this.mLogin + "-" + this.mPassword + "-" + this.mResource);
      this.mAdaptee.login(this.mLogin, this.mPassword, this.mResource);
      this.mUserInfo = new UserInfo(this.mAdaptee.getUser());
      this.mChatManager = new IKnowChatManager(this.mAdaptee.getChatManager(), this.mService);
      this.mIKnowUser = new MyIKnowUser(this.mAdaptee);
      this.mService.initJingle(this.mAdaptee);
      discoverServerFeatures();
      if (this.mAdaptee.getRoster() != null)
        this.mRoster = new RosterAdapter(this.mAdaptee.getRoster(), this.mAdaptee, this.mIKnowUser, this.mService, this.mAvatarManager);
      this.mApplication.setConnected(true);
      changeStatus(this.mPref.getInt("status", 0), this.mPref.getString("status_text", ""));
      authenticatContentUser();
      stopReconnecitonThread();
      i = 1;
    }
    catch (XMPPException localXMPPException)
    {
      Loger.e("XMPPConnectionAdapter", "Error while connecting", localXMPPException);
      if ((localXMPPException.getMessage().indexOf("not-authorized") != -1) || (localXMPPException.getMessage().indexOf("authentication failed") != -1))
        this.mErrorMsg = "用户名或者密码错误";
      while (true)
      {
        while (true)
        {
          while (true)
            i = 0;
          if (localXMPPException.getMessage().indexOf("conflict") == -1)
            break;
          this.mErrorMsg = "您在别处已上线";
        }
        this.mErrorMsg = "网络超时";
      }
    }
    catch (IllegalStateException localIllegalStateException)
    {
      Loger.e("XMPPConnectionAdapter", "Error while connecting", localIllegalStateException);
      this.mErrorMsg = "网络超时";
      i = 0;
    }
    catch (NullPointerException localNullPointerException)
    {
      Loger.e("XMPPConnectionAdapter", "Error while connecting", localNullPointerException);
      this.mErrorMsg = "网络超时";
      i = 0;
    }
  }

  public boolean loginWithNamePassword(String paramString1, String paramString2)
    throws RemoteException
  {
    this.mLogin = paramString1;
    this.mPassword = paramString2;
    return login();
  }

  public void removeConnectionListener(IBeemConnectionListener paramIBeemConnectionListener)
    throws RemoteException
  {
    if (paramIBeemConnectionListener != null)
      this.mRemoteConnListeners.unregister(paramIBeemConnectionListener);
  }

  public void setPrivacyListManager(PrivacyListManagerAdapter paramPrivacyListManagerAdapter)
  {
    this.mPrivacyListManager = paramPrivacyListManagerAdapter;
  }

  public void startReconnecitonThread()
  {
    this.mReconnectionStoped = false;
  }

  public void stopReconnecitonThread()
  {
    this.mReconnectionStoped = true;
  }

  private class ConnexionListenerAdapter
  implements ConnectionListener
  {
    private int randomBase = 5 + new Random().nextInt(11);
    private Thread reconnectionThread;

    private boolean isReconnectionAllowed()
    {
      int i;
      if (this.this$0.mReconnectionStoped)
        i = 0;
      while (true)
      {
        return i;
        i = 1;
      }
    }

    public void connectionClosed()
    {
      Loger.d("XMPPConnectionAdapter", "closing connection");
      XmppConnectionAdapter.access$2(this.this$0, null);
      XmppConnectionAdapter.access$3(this.this$0);
      reconnect();
    }

    public void connectionClosedOnError()
    {
      Loger.d("XMPPConnectionAdapter", "connectionClosedOnError");
      XmppConnectionAdapter.access$2(this.this$0, null);
      XmppConnectionAdapter.access$3(this.this$0);
      reconnect();
    }

    public void connectionFailed()
    {
      Loger.d("XMPPConnectionAdapter", "Connection Failed");
      int i = XmppConnectionAdapter.access$4(this.this$0).beginBroadcast();
      int j = 0;
      if (j >= i)
      {
        XmppConnectionAdapter.access$4(this.this$0).finishBroadcast();
        XmppConnectionAdapter.access$3(this.this$0);
        reconnect();
        return;
      }
      IBeemConnectionListener localIBeemConnectionListener = (IBeemConnectionListener)XmppConnectionAdapter.access$4(this.this$0).getBroadcastItem(j);
      if (localIBeemConnectionListener != null);
      try
      {
        localIBeemConnectionListener.connectionFailed(paramString);
        ++j;
      }
      catch (RemoteException localRemoteException)
      {
        while (true)
          Loger.w("XMPPConnectionAdapter", "Error while triggering remote connection listeners", localRemoteException);
      }
    }

    /**
     * @deprecated
     */
    public void reconnect()
    {
      monitorenter;
      try
      {
        if (isReconnectionAllowed())
        {
          if (this.reconnectionThread == null)
            break label31;
          boolean bool = this.reconnectionThread.isAlive();
          if (!(bool))
            break label31;
        }
        monitorexit;
        return;
        label31: this.reconnectionThread = new Thread(this)
        {
          private int attempts = 0;

          private int timeDelay()
          {
            int i;
            this.attempts = (1 + this.attempts);
            if (this.attempts > 13)
              i = 5 * 6 * XmppConnectionAdapter.ConnexionListenerAdapter.access$0(this.this$1);
            while (true)
            {
              while (true)
              {
                return i;
                if (this.attempts <= 7)
                  break;
                i = 6 * XmppConnectionAdapter.ConnexionListenerAdapter.access$0(this.this$1);
              }
              i = XmppConnectionAdapter.ConnexionListenerAdapter.access$0(this.this$1);
            }
          }

          public void run()
          {
            if (!(XmppConnectionAdapter.ConnexionListenerAdapter.access$1(this.this$1)))
              return;
            int i = timeDelay();
            if ((!(XmppConnectionAdapter.ConnexionListenerAdapter.access$1(this.this$1))) || (i <= 0));
            try
            {
              if ((!(XmppConnectionAdapter.ConnexionListenerAdapter.access$1(this.this$1))) || (XmppConnectionAdapter.access$1(XmppConnectionAdapter.ConnexionListenerAdapter.access$2(this.this$1)) == null) || (XmppConnectionAdapter.access$1(XmppConnectionAdapter.ConnexionListenerAdapter.access$2(this.this$1)).isConnected()) || (!(XmppConnectionAdapter.ConnexionListenerAdapter.access$2(this.this$1).connectSync())));
              XmppConnectionAdapter.ConnexionListenerAdapter.access$2(this.this$1).stopReconnecitonThread();
              this.this$1.reconnectionSuccessful();
              Loger.i("XMPPConnectionAdapter", "reconnect");
            }
            catch (RemoteException localRemoteException)
            {
              this.this$1.reconnectionFailed(localRemoteException);
            }
            catch (IllegalStateException localIllegalStateException)
            {
              try
              {
                Thread.sleep(1000L);
                this.this$1.reconnectingIn(--i);
              }
              catch (InterruptedException localInterruptedException)
              {
                while (true)
                {
                  while (true)
                  {
                    localInterruptedException.printStackTrace();
                    this.this$1.reconnectionFailed(localInterruptedException);
                  }
                  localIllegalStateException = localIllegalStateException;
                  this.this$1.reconnectionFailed(localIllegalStateException);
                }
              }
            }
          }
        };
        this.reconnectionThread.setName("Smack Reconnection Manager");
        this.reconnectionThread.setDaemon(true);
      }
      finally
      {
        monitorexit;
      }
    }

    public void reconnectingIn()
    {
      int i = XmppConnectionAdapter.access$4(this.this$0).beginBroadcast();
      int j = 0;
      if (j >= i)
      {
        XmppConnectionAdapter.access$4(this.this$0).finishBroadcast();
        return;
      }
      IBeemConnectionListener localIBeemConnectionListener = (IBeemConnectionListener)XmppConnectionAdapter.access$4(this.this$0).getBroadcastItem(j);
      if (localIBeemConnectionListener != null);
      try
      {
        localIBeemConnectionListener.reconnectingIn(paramInt);
        ++j;
      }
      catch (RemoteException localRemoteException)
      {
        while (true)
          Loger.w("XMPPConnectionAdapter", "Error while triggering remote connection listeners", localRemoteException);
      }
    }

    public void reconnectionFailed()
    {
      Loger.d("XMPPConnectionAdapter", "reconnectionFailed");
      int i = XmppConnectionAdapter.access$4(this.this$0).beginBroadcast();
      int j = 0;
      if (j >= i)
      {
        XmppConnectionAdapter.access$4(this.this$0).finishBroadcast();
        return;
      }
      IBeemConnectionListener localIBeemConnectionListener = (IBeemConnectionListener)XmppConnectionAdapter.access$4(this.this$0).getBroadcastItem(j);
      if (localIBeemConnectionListener != null);
      try
      {
        localIBeemConnectionListener.reconnectionFailed();
        ++j;
      }
      catch (RemoteException localRemoteException)
      {
        while (true)
          Loger.w("XMPPConnectionAdapter", "Error while triggering remote connection listeners", localRemoteException);
      }
    }

    public void reconnectionSuccessful()
    {
      Loger.d("XMPPConnectionAdapter", "reconnectionSuccessful");
      XmppConnectionAdapter.access$5(this.this$0).setConnected(true);
      int i = XmppConnectionAdapter.access$4(this.this$0).beginBroadcast();
      int j = 0;
      if (j >= i)
      {
        XmppConnectionAdapter.access$4(this.this$0).finishBroadcast();
        return;
      }
      IBeemConnectionListener localIBeemConnectionListener = (IBeemConnectionListener)XmppConnectionAdapter.access$4(this.this$0).getBroadcastItem(j);
      if (localIBeemConnectionListener != null);
      try
      {
        localIBeemConnectionListener.reconnectionSuccessful();
        ++j;
      }
      catch (RemoteException localRemoteException)
      {
        while (true)
          Loger.w("XMPPConnectionAdapter", "Error while triggering remote connection listeners", localRemoteException);
      }
    }
  }

  private class PingPacketListener
  implements PacketListener
  {
    public void processPacket()
    {
      if (!(paramPacket instanceof Ping))
        return;
      Ping localPing = new Ping();
      localPing.setPacketID(paramPacket.getPacketID());
      localPing.setType(IQ.Type.SET);
      try
      {
        XmppConnectionAdapter.access$1(this.this$0).sendPacket(localPing);
      }
      catch (IllegalStateException localIllegalStateException)
      {
        Loger.e("XMPPConnectionAdapter", localIllegalStateException.getMessage());
      }
    }
  }

  private class SubscribePacketListener
  implements PacketListener
  {
    public void processPacket()
    {
      PresenceAdapter localPresenceAdapter;
      if (!(paramPacket instanceof Presence))
        return;
      Presence localPresence1 = (Presence)paramPacket;
      if (localPresence1.getType() == Presence.Type.subscribe)
      {
        Presence localPresence2 = new Presence(Presence.Type.subscribed);
        localPresence2.setTo(localPresence1.getFrom());
        localPresenceAdapter = new PresenceAdapter(localPresence2);
      }
      try
      {
        XmppConnectionAdapter.access$6(this.this$0).getBind().sendPresencePacket(localPresenceAdapter);
      }
      catch (RemoteException localRemoteException)
      {
        do
          while (true)
            localRemoteException.printStackTrace();
        while (localPresence1.getType() == Presence.Type.unsubscribed);
        localPresence1.getType();
      }
    }
  }

  private class UserInfoManager
  implements AvatarListener
  {
    public void onAvatarChange(, String paramString2, List<AvatarMetadataExtension.Info> paramList)
    {
      if (StringUtils.parseBareAddress(XmppConnectionAdapter.access$7(this.this$0).getJid()).equalsIgnoreCase(StringUtils.parseBareAddress(paramString1)))
        XmppConnectionAdapter.access$7(this.this$0).setAvatarId(paramString2);
    }
  }
}